home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
MAPEDIT.ZIP
/
SAMPGAME
/
CYBER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-13
|
4KB
|
189 lines
#include "cyber.h"
struct token_struct area[99]={
{0,0,0,0,0},
{241,255,145,159,2}, /*up*/
{225,239,161,175,3}, /*left */
{257,271,161,175,4}, /*right*/
{241,255,177,191,5}, /*down*/
{241,255,161,175,1}, /*middle*/
{0,0,0,0,0}
};
unsigned int num_tokens=5;
main()
{
char temps[128];
unsigned int x,y;
unsigned int token;
if(!mousecheck())
{
printf("\nPlease install mouse driver!");
exit(0);
}
if(! (bufptr = (char far *)malloc(64001)))
{
printf("\nError allocating memory to bufptr.");
exit(0);
}
if(! (mapptr = (unsigned int far *)malloc(64001)))
{
printf("\nError allocating memory to mapptr.");
exit(0);
}
if(! (csptr = (unsigned char far *)malloc(64001)))
{
printf("\nError allocating memory to csptr.");
exit(0);
}
load_db();
vmode(0x13);
load_pcx("openscrn.pcx",bufptr);
show_screen();
load_map();
pause();
cls();
load_pcx("cyber.pcx",bufptr);
load_pcx("chset.pcx",csptr);
show_screen();
make_map();
show_map();
mousecursor(1);
for(;;)
{
x=mousecol();
y=mouserow();
sprintf(temps,"X: %3d Y: %3d",x,y);
putxys(25,1,temps);
if(kbhit())
{
switch(toupper(getch()))
{
case 0:
switch(getch())
{
case 45: /* alt-x */
token=1;
break;
}
break;
}
do_token(token);
}
if (mousebuttons())
{
do_token(chkmouse(x,y));
}
}
}
unsigned int chkmouse(unsigned int x,unsigned int y)
{
unsigned int token,loop;
token=0;
for(loop=1;loop<num_tokens+1;loop++)
{
if(x>area[loop].minx && x<area[loop].maxx && y>area[loop].miny && y < area[loop].maxy)
token=area[loop].token;
}
return(token);
}
do_token(unsigned int token)
{
if(!token)
return;
switch(token)
{
case 1:
exit_prog();
break;
case 2:
up();
break;
case 3:
left();
break;
case 4:
right();
break;
case 5:
down();
break;
}
}
wprintf(char *format,...)
{
char buffer[255];
va_list argument_ptr;
va_start(argument_ptr,format);
vsprintf(buffer,format,argument_ptr);
scrollw();
putxys(25,16,buffer);
}
scrollw()
{
unsigned int loop;
for(loop=TWOYS;loop<TWOYE-8;loop++)
{
memcpy(scrptr+loop*320+TWOXS,scrptr+(loop+8)*320+TWOXS,TWOXE-TWOXS+1);
}
for(loop=TWOYE-8;loop<TWOYE;loop++)
{
memset(scrptr+loop*320+TWOXS,0,TWOXE-TWOXS+1);
}
}
pause()
{
for(;;)
{
if(kbhit())
{
getch();
break;
}
if(mousebuttons())
break;
}
}
cls()
{
memset(scrptr,0,64000);
}
load_db()
{
FILE * fptr;
int loop;
if(!(fptr=fopen("sprites.dat","rb")))
{
printf("could not open Sprite Data file !");
exit(0);
}
fread(&db,sizeof(db),1,fptr);
fread(&si[0],sizeof(struct sprite_struct),100,fptr);
for(loop=0;loop<db.num_sprites;loop++)
{
if(!(si[loop].pict=(char far *) malloc(si[loop].width*si[loop].height)))
{
vmode(3);
printf("Error Allocating memory for sprite %d!",loop);
exit;
}
fread(si[loop].pict,si[loop].width*si[loop].height,1,fptr);
}
}